#ifndef ADDMODIFYCOMMODITY_H
#define ADDMODIFYCOMMODITY_H

#include <QWidget>
#include "commodity.h"

class InquireSql;
class CategorySettings;
class QLineEdit;
class AttributeSetting;

namespace Ui {
class AddModifyCommodity;
}

enum commodityPage{addCommodityPage, modifyCommodityPage};

class AddModifyCommodity : public QWidget
{
    Q_OBJECT
    
public:
    explicit AddModifyCommodity(QWidget *parent = 0);
    ~AddModifyCommodity();    
    bool eventFilter(QObject *target, QEvent *event);
    void displayAddModifyCommodity(int, int);
    enum LastClickAddModifyCommodity {lineEditCommodityBarcode = 2, lineEditName, lineEditInternalCode,
                   lineEditCategory, comboBoxSpecification, comboBoxColor, comboBoxBrand,
                   lineEditShelfLife, comboBoxUnit, lineEditCost,
                   lineEditDiscount, lineEditSellingPrice, lineEditMinStock,
                   lineEditMemberPrice, textEditRemark, pushButtonSave};

signals:
     void displayCommodityInformation();
     void signalDisplayAttributeSettings(int);

protected:
    void keyPressEvent(QKeyEvent *);

public slots:
    void slotUpdateComboBoxAttribute(int);

private slots:
    bool commodityIsEmpty(QString, QString);
    void on_pushButtonSave_clicked();
    void on_pushButtonCancel_clicked();
    void on_pushButtonAutoAddCommodityBarcode_clicked();

    void slotDisplayLineEditCategory(QString);


    void on_pushButtonAutoAddInternalCode_clicked();

    void on_lineEditCost_editingFinished();

    void on_lineEditSellingPrice_editingFinished();

    void on_lineEditMemberPrice_editingFinished();

    void on_pushButtonAddCategory_clicked();

    void on_pushButtonAddSpecification_clicked();

    void on_pushButtonAddColor_clicked();

    void on_pushButtonAddBrand_clicked();

    void on_pushButtonAddUnit_clicked();

private:
    void clearCommodity();
    int comboBoxAttributeItemNumber(int, const QString &);
    void initLineEdit();
    void completionPrice(QLineEdit *);

    Ui::AddModifyCommodity *ui;
    InquireSql *m_sql;
    commodityList m_list;
    CategorySettings *m_categorysettings;
    int currentPage;

    int m_lastClick;

    AttributeSetting *m_attributeSetting;
};

#endif // ADDMODIFYCOMMODITY_H
